<!DOCTYPE HTML>
<html lang="ru">
<head>
    <{header}>
    <!-- <link rel="stylesheet" href="images/styles.css" /> -->
	<link rel="canonical" href="http://<{$smarty.server.HTTP_HOST}><{$smarty.server.PATH_INFO}>"/>
    <{require file="block/head.html"}>
</head>
<body class="gallery-page">
<{require file="block/header.html"}>
<div class="container" id="gallery_filter">
    <div class="bread_crumbs"><{widgets id="bread_crumbs"}></div>
    <div class="row">

        <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12 pull-right xu_right">

            <div class="category-banner">
                <{$category.banner}>
            </div>

            <div id="filter_selected" class="filter-selected clearfix">
                <!--<div class="filter-clean text-right"><a href="javascript:Memory.clean('gallery.filter');location.reload();" class="btn btn-xs btn-default"><{t}>重置筛选项<{/t}></a></div>-->
                <dl class="filter-selected-list clearfix">
                    <dd class="filter-selected-values">
                        <div class="over_clean">
                            <h1 class="fl h1text"><{$category.title}></h1>
                            <p class="filter-title fl">
                                <span class="filter-title-text"><{t}>Вы нашли:&nbsp;всего<{/t}>&nbsp;<b class="op-search-result"><{if $total}><{$total}><{else}>0<{/if}></b></span>
                            </p>
                        </div>
                        <b class="filter-selected-title">Вы выбрали:</b>&nbsp;
                        <{foreach from=$active_filter item=item}>
                    <span class="filter-selected-entries" data-label="<{$item.label}>" data-single="true">
                      <label for="" class="filter-selected-label"><{$item.title}><{t}>：<{/t}></label>
                      <{foreach from=$item.options item=row}>
                      <span class="filter-selected-item" data-fid="<{$item.label}>-<{$row.data}>"><{$row.name}><a class="action-delete-filter icon iconfont" href="javascript:void(0);">&#xe62f;</a></span>
                      <{/foreach}>
                    </span>
                        <{/foreach}>


                    </dd>
                </dl>
            </div>
        </div>



        <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12 xu_leftbox">
            <!-- <a href='javascript:;' id='left-filter-success' style='margin:0px 0 10px;' onclick='javascript:getData2();return false;' class='btn btn-default btn-block'>Применить фильтр</a>-->
            <!-- Filter -->
            <div id="filter_container" class="filter-container filter-left">


                <!-- Filter elements -->
                <div  class="gallery-filter">
                    <div id="filter_lists" class="filter-lists-container">

                        <!-- Price-->
                        <{if $env.conf.b2c.gallery.display.price == 'true'}>
                        <dl class="filter-entries clearfix" data-label="price" data-single="true">
                            <dt class="filter-entries-label">
                                <{t}>价格：<{/t}>
                            </dt>
                            <dd class="posi_arr"><span class="fr iconfont">&#xe626;</span></dd>
                            <dd class="posi_round"></dd>
                            <dd class="filter-entries-values filter-non-fold">
                                <span class="filter-item <{if !$active_arr.price}>active<{/if}>"><a href="javascript:void(0);" class="handle action-select-unlimit"><{t}>不限<{/t}></a></span>
                                <{foreach from=$screen.price item=price_row}>
                  <span class="filter-item <{$price_row.active}>" data-fid="price-<{$price_row.min}>~<{$price_row.max}>"><a href="javascript:void(0);" class="handle action-select-filter">
                      <{if !$price_row.min && $price_row.max}>
                      <{t}>元以内<{/t}><{$price_row.max|cur}>
                      <{elseif $price_row.min && !$price_row.max}>
                      <{t}>元以上<{/t}><{$price_row.min|cur}>
                      <{else}>
                      <{$price_row.min}>-<{$price_row.max}><{t}> 元<{/t}>
                      <{/if}>
                  </a></span>
                                <{/foreach}>
                  <span class="filter-item" data-fid="price-custom">
                    <span class="filter-item-input">
                      <input type="text" name=""  class="action-filter-input form-control input-sm pull-left"><span class="input-seq">-</span><input type="text" name="" class="action-filter-input form-control input-sm pull-right" >
                      <div class="clearfix"></div>
                    </span>
                    <span class="filter-item-pop">
                      <a href="javascript:void(0);" class="action-reset-price btn btn-sm btn-danger"><{t}>清空<{/t}></a><button type="button" class="btn btn-sm btn-success action-confirm-price" id="action-confirm-price"><span><span><{t}>确定<{/t}></span></span></button>
                    </span>
                  </span>
                            </dd>
                        </dl>
                        <{/if}>

                        <!-- Brands -->
                        <{if $screen.brand}>
                        <dl class="filter-entries clearfix" data-label="brand_id">
                            <dt class="filter-entries-label">
                                <{t}>品牌<{/t}>
                            </dt>
                            <div class="posi_arr"><span class="fr iconfont">&#xe626;</span></div>
                            <dd class="posi_round"></dd>
                            <dd class="filter-entries-values brandbox">
                                <span class="filter-item <{if !$active_arr.brand}>active<{/if}>"><a href="javascript:void(0);" class="handle action-select-unlimit"><{t}>不限<{/t}></a></span>
                                <{foreach from=$screen.brand item=brand_row name=name}>
                                <{if $smarty.foreach.name.iteration == 999}>
                <span class="filter-item-hide">
                <{/if}>
                  <span class="filter-item <{$brand_row.active}>" data-fid="brand_id-<{$brand_row.brand_id}>" > <a href="javascript:void(0);" class="handle action-select-filter"><{$brand_row.brand_name}></a><a class="action-delete-filter icon iconfont" href="javascript:void(0);">&#xe62f;</a></span>
                <{if $smarty.foreach.name.iteration >1000 && $smarty.foreach.name.last }>
                </span>
                                <{/if}>
                                <{/foreach}>
                            </dd>

                            <{if count($screen.brand)>1000}>
                            <dd class="filter-entries-more action-unfold-entries"><a href="javascript:void(0);" class="btn btn-sm btn-default"><span class="text" data-toggle="<{t}>收起<{/t}>"><{t}>更多<{/t}></span><i class="icon" data-toggle="&#x37;">&#x36;</i></a></dd>
                            <{/if}>
                        </dl>
                        <{/if}>




                        <{assign var='filter_num' value=2}>
                        <!-- Attributes -->
                        <{if $screen.props}>
                        <{assign var='props_select' value=array()}>
                        <{foreach from=$screen.props item=props_row key=key}>
                        <{if $props_row.search == 'select'}>
                        <{assign var='props_select' value=array_merge($props_select,array($props_row))}>
                        <{continue}>
                        <{/if}>
                        <{assign var='filter_num' value=$filter_num+1}>
                        <{if $props_row.name != 'Скидка'}>
                        <dl class="filter-entries clearfix<{if $filter_num > 99 }> hide<{/if}><{if $key == '16' }> filter-hot<{/if}>" data-label="p_<{$key}>">
                            <dt class="filter-entries-label">
                                <{$props_row.name}>
                            </dt>
                            <dd class="posi_arr"> <span class="fr iconfont">&#xe626;</span></dd>
                            <dd class="posi_round"></dd>
                            <dd class="filter-entries-values">
                                <{if $props_row.active}>
                                <span class="filter-item"><a href="javascript:void(0);" class="handle action-select-unlimit"><{t}>不限<{/t}></a></span>
                                <{else}>
                                <span class="filter-item active"><a href="javascript:void(0);" class="handle action-select-unlimit"><{t}>不限<{/t}></a></span>
                                <{/if}>
                                <{foreach from=$props_row.options item=options_v key=options_k name=name}>
                                <{if $smarty.foreach.name.iteration == 999}>
                <span class="filter-item-hide">
                <{/if}>
                <span class="filter-item <{$props_row.active.[$options_k]}>" data-fid="p_<{$props_row.goods_p}>-<{$options_k}>"><a href="javascript:void(0);" class="handle action-select-filter"><{$options_v}></a><a class="action-delete-filter icon iconfont" href="javascript:void(0);">&#xe62f;</a></span>
                <{if $smarty.foreach.name.iteration >1000 && $smarty.foreach.name.last}>
                </span>
                                <{/if}>
                                <{/foreach}>
                            </dd>
                            <{if count($props_row.options)>999}>
                            <dd class="filter-entries-more action-unfold-entries"><a href="javascript:void(0);" class="btn btn-sm btn-default"><span class="text" data-toggle="<{t}>收起<{/t}>"><{t}>更多<{/t}></span><i class="icon" data-toggle="&#x37;">&#x36;</i></a></dd>
                            <{/if}>
                        </dl>
                        <{/if}> <!--Sales-->
                        <{/foreach}>
                        <{/if}>


                    </div>
                    <{if $spec_select || $props_select}>
                    <{assign var='filter_num' value=$filter_num+1}>
                    <div id="filter_dropdown" class="filter-dropdown-container<{if $filter_num >5}> hide<{/if}>">
                        <div class="filter-dropdown-inner clearfix">
                            <!-- Additional attributes dropdown -->
                            <{if $props_select}>
                            <{foreach from=$props_select item=props_row key=key}>
                            <dl class="filter-dropdown-item " data-label="p_<{$key}>">
                                <dt class="filter-dropdown-label"><{$props_row.name}><i class="icon">&#x36;</i></dt>
                                <dd class="filter-dropdown-values">
                                    <{if $props_row.active}>
                                    <span class="filter-item "><a href="javascript:void(0);" class="handle action-select-unlimit"><{t}>不限<{/t}></a></span>
                                    <{else}>
                                    <span class="filter-item active"><a href="javascript:void(0);" class="handle action-select-unlimit"><{t}>不限<{/t}></a></span>
                                    <{/if}>
                                    <{foreach from=$props_row.options item=options_v key=options_k}>
                                    <{/foreach}>
                                </dd>
                            </dl>
                            <{/foreach}>
                            <{/if}>

                            <!-- Specifications dropdown -->
                            <{if $spec_select}>
                            <{foreach from=$spec_select item=spec_row key=spec_id}>
                            <dl class="filter-dropdown-item" data-label="s_<{$spec_id}>">
                                <dt class="filter-dropdown-label"><{$spec_row.name}><i class="icon">&#x36;</i></dt>
                                <dd class="filter-dropdown-values">
                                    <span class="filter-item<{if not $spec_row.active}> active<{/if}>"><a href="javascript:void(0);" class="handle action-select-unlimit"><{t}>不限<{/t}></a></span>
                                    <{foreach from=$spec_row.spec_value item=spec_value key=spec_value_id}>
                                    <span class="filter-item <{$spec_row.active.[$spec_value_id]}>" data-fid="s_<{$spec_id}>-<{$spec_value_id}>"><a href="javascript:void(0);" class="handle action-select-filter"><{$spec_value.spec_value}></a><a class="action-delete-filter icon iconfont" href="javascript:void(0);">&#xe62f;</a></span>
                                    <{/foreach}>
                                </dd>
                            </dl>
                            <{/foreach}>
                            <{/if}>
                        </div>
                    </div>
                    <{/if}>

                    <{if $filter_num > 100}>
                    <div class="filter-more"><a href="javascript:void(0);" class="handle action-filter-more btn btn-sm btn-default" ><span class="text" data-toggle="<{t}>收起筛选项<{/t}>"><{t}>显示更多筛选项<{/t}></span><i class="icon" data-toggle="&#x37;">&#x36;</i></a></div>
                    <{/if}>
                    <!-- Advertising tickets -->

                </div>
            </div>
            <div class="hidden-xs">
                <{widgets id="lsidebar"}>
            </div>
						
        </div>
        <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12 xu_right">

            <{main}>
        </div>
    </div>
</div>
<div class="loding" style="width:100%; height:100%; position:fixed; top:0; left:0;z-index:9999999999;display:none;"><div style="width:100px;margin:20% auto;color:#000; "><{img style="display:block;width:100%;" src="images/loading_blue.gif"  app="b2c"}></div></div>
<{assign var='imageset' value=$env.conf.image.image.set}>
<script>
    jQuery(function(){
        jQuery('.filter-entries') .each(function (){
            var heiiwn=jQuery(this).find(".filter-entries-values").height();
            jQuery(this).find(".filter-entries-values").css({'top':-(heiiwn/2-5)});
        });
        jQuery('.filter-entries').last().find('dt').css('border-bottom','1px solid #fff');
        var wind_wid = jQuery(window).width();
        if(wind_wid<760){
            jQuery('.xu_leftbox').css('width','100%');
            jQuery('.xu_right').css('width','100%');
        }else{
            jQuery('.xu_leftbox').css('width','21%');
            jQuery('.xu_right').css('width','79%');
        }
        jQuery(window).resize(function () {
            var wind_wid = jQuery(window).width();
            //console.log(wind_wid);
            if(wind_wid<760){
                jQuery('.xu_leftbox').css('width','100%');
                jQuery('.xu_right').css('width','100%');
            }else{
                jQuery('.xu_leftbox').css('width','21%');
                jQuery('.xu_right').css('width','79%');
            }
        });
        if(wind_wid>1200){
            jQuery('.filter-entries-label').click(function(){
                jQuery(this).css('border-bottom','1px solid #cecece');
                jQuery(this).parent().prev().children('.filter-entries-label').css('border-bottom','1px solid #cecece');

            });
            jQuery(".filter-entries").hover(function(){
                        jQuery(this).prev().find('dt').css('border-bottom','1px solid #fff');
                        jQuery(this).find('dt').css('border-bottom','1px solid #fff');
                        jQuery(this).addClass('showder');
                        //  if(jQuery(this).hasClass('open')){
                        //      jQuery(this).addClass('open');
                        //   }
                        // else{
                        jQuery(".filter-entries").each(function(){
                            jQuery(this).removeClass('open');
                        });
                        jQuery(this).addClass('open');
                        //  }
                    },
                    function(){
                        jQuery(this).prev().find('dt').css('border-bottom','1px solid #cecece');
                        jQuery(this).find('dt').css('border-bottom','1px solid #cecece');
                        jQuery('.filter-entries').last().find('dt').css('border-bottom','1px solid #fff');
                        //jQuery(this).removeClass('open');
                        var loding_box =jQuery('.loding').css('display');
                        if(loding_box=='none') {
                            jQuery(this).removeClass('open');
                            jQuery(this).removeClass('showder');
                        }else{
                            jQuery(this).addClass('open');
                            jQuery(this).addClass('showder');
                        }
                    });
        }
        else{
            jQuery(".filter-entries").click(function(){
                    jQuery(this).addClass('showder');
                    jQuery(this).addClass('open').siblings().removeClass('open');
            });
        }
    });
    /*    setTimeout(function () {
     jQuery('.posi_num').hide();
     }, 1000);*/
    var Router = {
        'filter': {
            query: '<{link app=b2c ctl=site_gallerybag act=ajax_get_goods}>'

        }
    };
    var Query = function(url, data, update, options) {
        var self = this;
        this.update = function(url, data, update, options) {
            if(typeof(update) == 'object') {
                update = Module.gallery.show;
            }
            options = Object.merge({
                url: url,
                link: 'ignore',
                update: update
            }, options || {});
            new Request.HTML(options).post(data);
        };
        this.filter = function(data, fn){
            var url = Router.filter.query;
            var mask = new Class({
                options: {
                    width: '100%',
                    height: '100%',
                    'class': 'mini-mask',
                    'html': '<span class="mask-loading"></span>',
                    'effect': false,
                    position: true,
                    pins: true
                }
            });

            if(Browser.ie) {
                mask.element.setStyle('background-color', Browser.version == 9 ? 'rgba(255,255,255,0.1)' : '');
            }
            self.update(url,data,Module.gallery.show, {
                onRequest:function() {
                    jQuery('.loding').show();
                    jQuery('#gallery_show').html('Идёт загрузка каталога......');
                    jQuery('.category-text').hide();
                    //mask.show();
                },
                onSuccess:function(rs){
                    //*show一直报错，我自己写的------------------zz
                    jQuery('.loding').hide();
                    jQuery('.category-text').show();
                    var num_change =  jQuery('.action-pagedata').val();

                    if(num_change){
                        var check_num =num_change.split(':');
                        var want_num = check_num[1];
                        var last_num = want_num.split(',');
                        var last_want = last_num[0];
                        jQuery('.posi_num').fadeIn(1000);
                        jQuery('.op-search-result').text(last_want);
                        jQuery('.posi_num').text(last_want);

                    }else{
                        jQuery('.op-search-result').text('0');
                        jQuery('.posi_num').text('0');
                    }

                    jQuery('.posi_num').delay(2000).fadeOut(1500);
                    //mask.hide();
                    new DataLazyLoad({img:'data-src', lazyDataType:'img',onAfter:function(img){
                        if(Browser.ie6) fixImageSize(img);
                    }});
                    setGridSize(Module.gallery.show.getElements('.gallery-grid .goods-item'), ['.goods-name', '.promotion-tags'], 4);
                    updateNum();
                    miniCart.init();
                    fn&&fn(rs);
                    /*  jQuery('.posi_round').css('display','none');
                     jQuery('.filter-entries-values').each(function(){
                     jQuery(this).find('.filter-item').each(function(){
                     if(jQuery(this).attr('class').indexOf('active')>1){
                     jQuery(this).parents('.filter-entries-values').siblings('.posi_round').css('display','block');
                     }
                     });
                     });*/
                    posi_round();


                  /*  页码效果===============================================star*/
                    var url  = window.location.href;
                    var page_num ='';
                    jQuery('.pageview .flip').each(function(){
                        if(jQuery(this).hasClass('active')){
                            page_num=jQuery(this).text();
                        }
                    });
                    if(url.indexOf('page')>0){
                        var _params = url.split("page");
                        var b =url.substring(url.lastIndexOf(_params[1]));
                        var c = url.substring(url,url.lastIndexOf(_params[1]));
                        url = c +'='+page_num;
                        history.pushState({},"",url);
                    }else{
                        if(jQuery('.pageview').length>0){
                            if(url.indexOf('&')>0){
                                history.pushState({},"",url+'page='+page_num);
                            }else{
                                history.pushState({},"",url+'?page='+page_num);
                            }
                        }
                    }
                    /*  页码效果===============================================end*/
                }
            });
        };
        //;jQuery('.posi_num').fadeTo(5000,1).hide();
        //setTimeout(jQuery('.posi_num').hide(),300);
        this.addtocart = function(url, data, target) {
            var form = $('_addtocart_submitform') || new Element('form#_addtocart_submitform',{
                        action: url,
                        method: 'post',
                        target: target,
                        style: 'display:none'
                    }).inject(document.body);
            var formElements = Array.from(data).invoke('clone', false);
            form.empty().adopt(formElements).submit();
        };
    };
    Query = new Query;
    Module = new Module('gallery', ['filter', {'selected': 'filter_selected'}, 'sortbar', 'show', 'compare']);

    if(jQuery('.breadcrumbs span').length>=10){
        jQuery('#filter_lists dl').each(function(){
            if(jQuery(this).attr('data-label')=='p_2'){
                jQuery(this).remove();
            }
        });
    }

    jQuery('#filter_selected .filter-selected-entries').each(function(){
        if(jQuery(this).attr("data-single")=="true"){
            jQuery(this).css('margin-right','0');
        }
    });
    //-------------zhenhen------------
    jQuery('.filter-item').removeClass('active');
    jQuery('.filter-selected-values').children("span").empty();
    var url  = window.location.href;
    url = url.substring(url.lastIndexOf("?")+1);
    var _params = url.split("&");
    var datafids=new Array();
    var box3;

    for(var i=0;i<_params.length;i++){
        var _value  =_params[i].split("=");
        var  name=_value[0];
        var spa;
        var dlls;
        var keyword;
        if(name.indexOf("[")>-1){
            var datafile=name.substring(0,name.indexOf("["))+"-"+_value[1];
            var lableval=name.substring(0,name.indexOf("["));
            spa = Module.gallery.filter.getElements('[data-fid='+datafile+']');
            jQuery(spa).addClass("active");
            if(datafids.length>0&&datafids.indexOf(lableval)==-1){
                jQuery('.filter-selected-values').append(box3);
                box3='';
                datafids.length=0;
                /* alert(box3);*/
            }
            if(datafids.indexOf(lableval)==-1){
                dlls = Module.gallery.filter.getElements('[data-label='+lableval+']');
                keyword= Module.gallery.filter.getElements('[data-fid='+datafile+']');
                var lablehtm=jQuery(dlls).children().html();
                var keywordhtm=jQuery(keyword).children('.action-select-filter').eq(0).text();
                datafids.push(lableval);
                if(lableval=='price'){
                    var price_arr = datafile.split('-');
                    keywordhtm =  price_arr[1] ;
                    var all_max = keywordhtm.split('~');
                    var minno = all_max[0];
                    var maxno = all_max[1];
                    keywordhtm = minno+"~"+maxno+' руб.';
                    if(maxno =='99999999'){
                        maxno='от';
                        keywordhtm ='от '+minno+' руб.';
                    }

                }
                box3 = '<span class="filter-selected-entries" data-label="'+lableval+'">'+'<label class="filter-selected-label">'+lablehtm+'</label><span class="filter-selected-item" data-fid="'+datafile+'">'+keywordhtm+'<a class="action-delete-filter icon iconfont" href="javascript:void(0);">&#xe62f;</a></span></span>';
            }else if(datafids.indexOf(lableval)>-1){
                box3=box3.substring(0,box3.lastIndexOf("</span>"));
                dlls = Module.gallery.filter.getElements('[data-label='+lableval+']');
                keyword= Module.gallery.filter.getElements('[data-fid='+datafile+']');
                var lablehtm=jQuery(dlls).children().html();
                var keywordhtm=jQuery(keyword).children('.action-select-filter').eq(0).text();
                box3 += '<span class="filter-selected-item" data-fid="'+datafile+'">'+keywordhtm+'<a class="action-delete-filter icon iconfont" href="javascript:void(0);">&#xe62f;</a></span>';
                box3 +='</span>';
            }
        }
    }
    jQuery('.filter-selected-values').append(box3);

    var url  = window.location.href;
    url = url.substring(0,url.lastIndexOf("?"));
    jQuery('.filter-clean a') .click(function(event) {
        jQuery(this).attr('href',url);
    });

    jQuery('.compare-fav-wrap button').click(function(){
        jQuery(this).css('color','#ffaf01');
    });
    //zz-  关于重置按钮
    var chosed_num = jQuery('.filter-selected-list .filter-selected-values .filter-selected-entries').length;
    var reset = '<a class="reset_btn">Снять все</a>';
    var reset_url = window.location.pathname;
    if(chosed_num>0){
        jQuery('.filter-selected-list .filter-selected-values').append(reset);
        jQuery('b.filter-selected-title').css('display','inline-block');
        jQuery('.reset_btn').css('display','inline-block');
        jQuery('#left-filter-success').removeClass('btn-default').addClass('btn-success');
    }
    jQuery('body').on('click',".reset_btn",function(){
        window.location.href = reset_url;
    });

    //-------------zhenhen end------------
    function posi_round (){
        jQuery('.posi_round').css('display','none');
        jQuery('.filter-entries-values').each(function(){
            jQuery(this).find('.filter-item').each(function(){
                if(jQuery(this).attr('data-fid')){
                    if(jQuery(this).attr('class').indexOf('active')>1){
                        jQuery(this).parents('.filter-entries-values').siblings('.posi_round').css('display','block');
                    }
                }
            });
        });
    }
    function quest_value(thisobj){
        var props_value_id ="";
        var cat_id='<{$screen.cat_id}>'?'<{$screen.cat_id}>':'';
        var virtual_id='<{$filter.virtual_cat_id}>'?'<{$filter.virtual_cat_id}>':'';
        cat_id=parseInt(cat_id);
        virtual_id=parseInt(virtual_id);
        var select_all ='';
        // var loadingbox ='<div class="loding"><div style="color:#000; "><{img style="display:block;width:100%;" src="images/loading_blue.gif"  app="b2c"}></div></div>';
        var select_id ='';
        var select_type =0;
        if(cat_id=='NaN' || cat_id==97){
            cat_id=0;
        }
        if(virtual_id=='NaN'){
            virtual_id=0;
        }
        jQuery('.filter-selected-list .filter-selected-item').each(function(){
            props_value_id += jQuery(this).attr('data-fid')+",";
        });
        if(thisobj){
            var this_class= thisobj.attr('class');
            if(this_class.indexOf('select')>1){
                // 点击不限的时候
                if(this_class.indexOf('unlimit')>1){
                    select_all=thisobj.parents('.filter-entries').attr('data-label');
                }else{
                    select_type=1;
                    select_id = thisobj.parents('.filter-item').attr('data-fid');
                    select_all=0;
                }
            }else{

                select_type=0;
                if(thisobj.parent().attr('class')=='filter-selected-item'){
                    select_id = thisobj.parents('.filter-selected-item').attr('data-fid');
                }else{
                    select_id = thisobj.parents('.filter-item').attr('data-fid');
                }

            }
        }else{
            var this_url =window.location.href;
            if(this_url.indexOf('[]')){
               var last_post = jQuery('.reset_btn').prev().children().last().attr('data-fid');
                select_id=last_post;
            }

            select_type=1;
        }
        /*if(thisall){
         alert();
         var this_lable =thisall.parents('.filter-entries').attr('data-label');
         alert(this_lable);
         }*/
        // jQuery('.loding').remove();
        /* if(thisobj){
         thisobj.parents('.filter-entries-values').append(loadingbox);
         }*/
        if(props_value_id){
            props_value_id = props_value_id.substring(0,props_value_id.length-1);
        }
        jQuery('.filter-item .action-select-filter').each(function() {
            jQuery(this).addClass("forbid");
        });
        jQuery.ajax({
            url: "<{link app=b2c ctl=site_gallerybag act=filter_ajax}>",
            type:'post',
            async:true,
            dataType:'json',
            data:{'props_value_id':props_value_id,'cat_id':cat_id,'virtual_id':virtual_id,'select_id':select_id,'select_type':select_type,'select_all':select_all},
            success: function(rs){
                //  jQuery('#gallery_filter .loding').remove();
                var props_value_id  = new Array();
                var brand_fid  = new Array();
                jQuery.each(rs.props,function() {
                    var goods_p  = this.goods_p;
                    // console.log(this.options);
                    if(this.options){
                        jQuery.each(this.options,function(i,v) {
                            props_value_id.push("p_"+goods_p+"-"+i);
                            // props_value_id.push(i);
                        });
                    }
                });
                jQuery.each(props_value_id,function(e,vle) {
                    jQuery("span[data-fid='"+vle+"']").find(".action-select-filter").removeClass("forbid");
                });
                jQuery.each(rs.brand,function(e,l) {
                    //console.log(l);
                    brand_fid.push("brand_id-"+l);
                    // console.log('brand_fid:'+brand_fid.join(","));

                });
                jQuery.each(brand_fid,function(e2,l2) {
                    jQuery("span[data-fid='"+l2+"']").find(".action-select-filter").removeClass("forbid");
                    jQuery("span[data-fid='"+l2+"']").css('display','inline-block');


                });
                jQuery('.brandbox .forbid').each(function(){
                    //console.log(jQuery(this).parent().attr('data-fid'));
                    jQuery(this).parent().css('display','none');
                });
                jQuery('.filter-non-fold a').removeClass('forbid');
                jQuery('.filter-entries') .each(function (){
                    var heiiwn=jQuery(this).find(".filter-entries-values").height();
                    jQuery(this).find(".filter-entries-values").css({'top':-(heiiwn/2-5)});
                });
            },
        });


    }
    jQuery(document).ready(function() {
        quest_value();
        posi_round();
    });
    var hides = Module.elements('gallery.filter', '.hide');
    Module.gallery.filter.addEvents({
        'click:relay(.action-select-filter)': function(e){
            if(jQuery(this).attr('class').indexOf('forbid')<0){
                var thisobj= jQuery(this);
                var props_value_id ="";
                var append_num = '<dd class="posi_num"></dd>';
                //var all__data_value=props_value_id+','+cat_id;
                var item = this.getParent('.filter-item');
                if(item.hasClass('active')) return;
                setCustom(item);
                setFilter(this, item);
                item.addClass('active');
                // jQuery(this).css('background','#ffaf01');
                jQuery('.filter-item .handle.action-select-filter').attr('disabled',"true");
                jQuery('.filter-selected-title').css('display','inline-block');
                jQuery('#left-filter-success').removeClass('btn-default').addClass('btn-success');
                if(jQuery('.filter-selected-values .reset_btn').length<=0){
                    jQuery(".filter-selected-entries:last-child").after('<a class="reset_btn">Снять все</a>');
                }else{
                    jQuery('.filter-selected-values .reset_btn').eq(0).remove();
                    jQuery(".filter-selected-entries:last-child").after('<a class="reset_btn">Снять все</a>');
                }
                jQuery('.filter-selected-list .filter-selected-item').each(function(){
                    props_value_id += jQuery(this).attr('data-fid')+",";
                });
                if(props_value_id){
                    props_value_id = props_value_id.substring(0,props_value_id.length-1);
                }
                jQuery('.posi_num').remove();
                jQuery(this).parents('.filter-entries').append(append_num);
                jQuery(this).parents('.filter-entries').addClass('open');
                quest_value(thisobj);

                /* if(load.indexOf('cat_id')){
                 alert();
                 }*/
                /*   var noyes = url.split("?");
                 alert(noyes);*/
                var _data =getData_no1();

                history.pushState({},"",url+'?'+_data);
                //  if(first_num==false){
                //    alert();
                //      history.pushState({},"",window.location.href+'?'+getData());
                //      first_num=true;
                //  }else{
                //      history.pushState({},"",getData());
                //  }

                //history.pushState({},"",window.location.href+"//qizhenzhen");
                //  history.pushState({},"","www.baidu.com");
                // var all__data_value=props_value_id+','+cat_id;
                //var lodingbox='<div class="loding" style="width:100%; height:100%; position:fixed; top:0; left:0;z-index:9999999999;"><div style="width:100px;margin:20% auto;color:#000; "><{img style="display:block;width:100%;" src="images/loading_blue.gif"  app="b2c"}></div></div>';
                //  jQuery('#gallery_filter').append(lodingbox);

                /*  var str = '{"props":{"1":{"name":"\u0421\u0435\u0437\u043e\u043d","goods_p":"1","search":"nav","type":"select","show":"on","options":{"10":"\u0414\u0435\u043c\u0438\u0441\u0435\u0437\u043e\u043d","11":"\u0417\u0438\u043c\u0430"},"active":[]},"2":{"name":"\u0412\u0438\u0434 \u043e\u0431\u0443\u0432\u0438","goods_p":"2","search":"nav","type":"select","show":"on","options":{"135":"\u0411\u043e\u0442\u0438\u043d\u043a\u0438"},"active":[]},"3":{"name":"\u0412\u043e\u0437\u0440. \u0433\u0440\u0443\u043f\u043f\u0430","goods_p":"3","search":"nav","type":"select","show":"on","options":null,"active":[]},"4":{"name":"\u0414\u0435\u0442\u0441\u043a\u0438\u0439 \u043f\u043e\u043b","goods_p":"4","search":"nav","type":"select","show":"on","options":null,"active":[]},"5":{"name":"\u041a\u043e\u043b-\u0432\u043e \u043f\u0430\u0440. \u0432 \u0443\u043f.","goods_p":"5","search":"nav","type":"select","show":"on","options":{"78":"8","79":"10","80":"12"},"active":[]},"6":{"name":"\u0426\u0432\u0435\u0442","goods_p":"6","search":"nav","type":"select","show":"on","options":{"82":"\u0411\u0435\u043b\u044b\u0439","84":"\u0411\u043e\u0440\u0434\u043e\u0432\u044b\u0439","87":"\u0417\u0435\u043b\u0435\u043d\u044b\u0439","90":"\u041a\u043e\u0440\u0438\u0447\u043d\u0435\u0432\u044b\u0439","333":"\u0421\u0435\u0440\u0435\u0431\u0440\u043e","335":"\u0421\u0438\u043d\u0438\u0439","341":"\u0427\u0435\u0440\u043d\u044b\u0439"},"active":[]},"7":{"name":"\u041c\u0430\u0442-\u043b \u043f\u043e\u0434\u043a\u043b\u0430\u0434\u0430","goods_p":"7","search":"nav","type":"select","show":"on","options":{"99":"\u0418\u0441\u043a. \u043c\u0435\u0445","100":"\u0418\u0441\u043a. \u0437\u0430\u043c\u0448\u0430","102":"\u0418\u0441\u043a. \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b","104":"\u0418\u0441\u043a. \u043d\u0443\u0431\u0443\u043a","105":"\u041a\u043e\u043c\u0431. \u0438\u0441\u043a. \u043c\u0430\u0442-\u043b\u044b","106":"\u041a\u043e\u043c\u0431. \u043c\u0430\u0442-\u043b\u044b","346":"\u041d\u0430\u0442\u0443\u0440. \u043c\u0435\u0445","350":"\u0422\u0435\u043a\u0441\u0442\u0438\u043b\u044c","352":"\u0428\u0435\u0440\u0441\u0442\u044c","353":"\u042d\u0412\u0410"},"active":[]},"8":{"name":"\u0418\u043d\u0434\u0438\u0432. \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0430","goods_p":"8","search":"nav","type":"select","show":"on","options":{"108":"\u041a\u043e\u0440\u043e\u0431\u043a\u0430","109":"\u041f\u043e\u043b\u0438\u044d\u0442\u0438\u043b\u0435\u043d\u043e\u0432\u0430\u044f \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0430"},"active":[]},"9":{"name":"\u041a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f","goods_p":"9","search":"nav","type":"select","show":"on","options":{"112":"\u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u0430\u044f"},"active":[]},"10":{"name":"\u0420\u0430\u0437\u043c\u0435\u0440\u043d\u044b\u0439 \u0440\u044f\u0434","goods_p":"10","search":"nav","type":"select","show":"on","options":{"267":"36-41","284":"39-44","290":"40-45","291":"40-46","292":"40-47","296":"41-45","297":"41-46"},"active":[]},"11":{"name":"\u041c\u0430\u0442-\u043b \u0432\u0435\u0440\u0445\u0430","goods_p":"11","search":"nav","type":"select","show":"on","options":{"324":"\u041a\u043e\u043c\u0431. \u043d\u0430\u0442\u0443\u0440. \u043c\u0430\u0442-\u043b\u044b","325":"\u041a\u043e\u043c\u0431. \u0438\u0441\u043a. \u0438 \u043d\u0430\u0442\u0443\u0440. \u043c\u0430\u0442-\u043b\u044b","329":"\u041d\u0430\u0442\u0443\u0440. \u043a\u043e\u0436\u0430"},"active":[]}}}';
                 var contact = JSON.parse(str);
                 var props_value_id  = new Array();
                 var props_id  = new Array();
                 jQuery.each(contact.props,function() {
                 var goods_p  = this.goods_p;
                 props_id.push("p_"+goods_p);
                 if(this.options){
                 jQuery.each(this.options,function(i,v) {
                 props_value_id.push("p_"+goods_p+"-"+i);
                 // props_value_id.push(i);
                 });
                 }
                 });
                 jQuery('.filter-item a').each(function() {

                 jQuery(this).addClass("forbid");
                 });
                 jQuery.each(props_value_id,function(e,vle) {
                 //                alert("props_value_id:"+vle+","+jQuery("span[data-fid='"+vle+"']").html());
                 jQuery("span[data-fid='"+vle+"']").find("a").removeClass("forbid");
                 });*/
                // alert("props_value_id:"+props_value_id.join(","));props_id
                //alert("props_id:"+props_id.join(","));
                //create new url
//            history.pushState({},"",window.location.href+"//qizhenzhen");




                //----------------ruru star-----------
//            jQuery("#top-filter-line").detach();
//            jQuery(".filter-selected-list").append("<div id='top-filter-line'><div class='container'><a href='#' onclick='javascript:getData2();return false;' class='btn btn-success btn-sm pull-right'>Применить фильтр</a><a href='"+location.pathname+"'  class='btn btn-danger btn-sm pull-right' >Очистить фильтр</a></div></div>");
//              jQuery("#content-filter-success").detach();
                // jQuery(".filter-clean a").before("<a href='#' id='content-filter-success' style='margin-right:6px;' onclick='javascript:getData2();return false;' class='btn btn-success btn-sm'>Применить фильтр</a>");
                //     jQuery("#left-filter-success").detach();
//            jQuery("#filter_container").after("<a href='#' id='left-filter-success' style='margin:-20px 0 20px;' onclick='javascript:getData2();return false;' class='btn btn-success btn-block'>Применить фильтр</a>");
                //----------------ruru end-----------
                // getData2();
                Query.filter(_data);
            }
        },
        'click:relay(.action-select-unlimit)':function(e){
            var thisobj= jQuery(this);
            var item = this.getParent('.filter-item');
            if(item.hasClass('active')) return;
            var actives = item.getParent().getElements('.active');
            var label = this.getParent('[data-label]').get('data-label');
            if(actives.length) {
                actives.removeClass('active');
            }
            try{
                Module.gallery.selected.getElement('[data-label='+label+']').destroy();
            }catch(e){}
            setCustom(item);
            item.addClass('active');
            jQuery('.filter-selected-entries').each(function(){
                if(jQuery(this).attr('data-label')==label){
                    jQuery(this).remove();
                }
            });
            jQuery(this).parents('.filter-entries').addClass('open');
            quest_value(thisobj);
            var _data =getData_no1();
            history.pushState({},"",url+'?'+_data);
            Query.filter(_data);
        },
        'click:relay(.action-delete-filter)':function(e) {

            var isSelect = this.getParent('.filter-selected') ? '-selected' : '';
            var el = this.getParent('.filter'+isSelect+'-item');
            var id = el.get('data-fid');
            var els;
            var sel;
            var thisobj= jQuery(this);
            if( jQuery('.filter-selected-values .filter-selected-item').length<=1){
                jQuery('b.filter-selected-title').css('display','none');
                jQuery('.reset_btn').css('display','none');
            }

            if(isSelect) {
                sel = el;
                els = Module.gallery.filter.getElements('[data-fid='+id+']');
                el = els.length > 1 ? els[1] : Module.gallery.filter.getElement('[data-fid$=custom]');
            }
            else {
                sel = Module.gallery.selected.getElement('[data-fid='+id+']');
            }
            jQuery(this).parents('.filter-entries').addClass('open');
            jQuery(this).parents('.filter-entries').addClass('showder');
            delFilter(el, sel);
            var _data =getData_no1();
            history.pushState({},"",url+'?'+_data);
            //------ruru star----------
//            jQuery("#top-filter-line").detach();
//            jQuery(".filter-selected-list").append("<div id='top-filter-line'><div class='container'><a href='#' onclick='javascript:getData2();return false;' class='btn btn-success btn-sm pull-right'>Применить фильтр</a><a href='"+location.pathname+"'  class='btn btn-danger btn-sm pull-right'>Очистить фильтр</a></div></div>");
            //jQuery("#content-filter-success").detach();
            //jQuery(".filter-clean a").before("<a href='#' id='content-filter-success' style='margin-right:6px;' onclick='javascript:getData2();return false;' class='btn btn-success btn-sm'>Применить фильтр</a>");
//            jQuery("#left-filter-success").detach();
//            jQuery("#filter_container").after("<a href='#' id='left-filter-success' style='margin:-20px 0 20px;' onclick='javascript:getData2();return false;' class='btn btn-success btn-block'>Применить фильтр</a>");
            //-----------ruru end-----------------
            //getData2();
            Query.filter(_data);
            quest_value(thisobj);
        },
        'click:relay(.action-unfold-entries)':function(e){
            e.preventDefault();
            this.getParent().getElement('.filter-item-hide').toggleClass('filter-item-show');
            toggleText(this.getElement('.text'));
            toggleText(this.getElement('.icon'));
        },
        'focus:relay(.action-filter-input)':function(e){
            var parent = this.getParent('.filter-item');
            clearTimeout(parent.timer);
            parent.addClass('filter-pop-active');
            if(!parent.outerclick) parent.getDocument().addEvent('click', function(e){
                parent.outerclick = true;
                if(!parent.contains($(e.target))) hideFilterPop(parent);
            });
        },
        'mouseenter:relay(.filter-pop-active)':function(e){
            clearTimeout(this.timer);
        },
        'mouseleave:relay(.filter-pop-active)':function(e){
            this.timer = hideFilterPop.delay(2000, this,this);
        },
        'click:relay(.action-reset-price)':function(e){
            e.preventDefault();
            this.getParent('.filter-item').getElements('.action-filter-input').set('value', '')[0].focus();
        },
        'inputchange:relay(.action-filter-input)': function(){
            if(!this.value.test(/^(0|[1-9][0-9]*)?$/)) {
                this.value = this.value.substr(0, this.value.length - 1);
            }
        },
        'click:relay(.action-confirm-price)':function(e){

            var parent = this.getParent('.filter-item');
            var input = parent.getElements('.action-filter-input');
            var min = input[0].value;
            var max = input[1].value;
            if(min == max) return;
            if(min == '') min = 0;
            if(max == '') max = 99999999;
            if(isNaN(min) || isNaN(max)) return;
            if(min - max > 0) {
                var tmp = min;
                min = max;
                max = tmp;
            }
            min = +min;
            max = +max;
            var value = min;
            if(max == 99999999) {
                value= 'от '+value+' руб.';
            }

            else value += '-' + max + '<{t}>元<{/t}>';
            input[0].value = min;
            input[1].value = max;
            setFilter(this, parent, value, min, max);
            hideFilterPop(this.getParent('.filter-item'));
            var _data =getData_no1();
            history.pushState({},"",url+'?'+_data);
            //-------ruru-----------
            jQuery('#left-filter-success').removeClass('btn-default').addClass('btn-success');

            //jQuery("#content-filter-success").detach();
            // jQuery(".filter-clean a").before("<a href='#' id='content-filter-success' style='margin-right:6px;' onclick='javascript:getData2();return false;' class='btn btn-success btn-sm'>Применить фильтр</a>");
            //--------ruru end-----------
            var _data =getData_no1();
            history.pushState({},"",url+'?'+_data);
            Query.filter(_data);
        },
        'click:relay(.filter-dropdown-label)':function(e) {
            var parent = this.getParent();
            parent.toggleClass('current');
            if(!parent.outerclick) parent.getDocument().addEvent('click', function(e){
                parent.outerclick = true;
                if(!parent.contains($(e.target))) hideDropdown(parent);
            });
        },
        'mouseenter:relay(.filter-dropdown-item)':function(e){
            clearTimeout(this.timer);
        },
        'mouseleave:relay(.filter-dropdown-item)':function(e){
            this.timer = hideDropdown.delay(1000, this, this);
        },
        'click:relay(.action-filter-more)':function(e) {
            e.preventDefault();
            hides.toggleClass('hide');
            toggleText(this.getElement('.text'));
            toggleText(this.getElement('.icon'));
        }
    });
    Module.gallery.sortbar.addEvents({
        'click:relay(.action-sort)':function(e){
            e.preventDefault();
            toggleOrderby(this);

            if(!this.hasClass('active') || this.match('[class*=price-]')) {
                Query.filter(getData());
            }
            toggleActive(this);
        },
        'change:relay(.action-orderby)':function(e) {
            var sort = Module.elements('gallery.sortbar','.action-sort');
            var hl = sort.every(function(s){
                var sortby = s.get('data-sort');
                var order = this.value;
                if(order.indexOf('price ') === 0 && sortby.indexOf('price ') === 0) {
                    if(order !== sortby) {
                        toggleOrderby(s, false);
                    }
                    toggleActive(s);
                    return false;
                }
                if(order == sortby) {
                    toggleActive(s);
                    return false;
                }
                return true;
            }, this);
            if(hl) sort.removeClass('active');
            Query.filter(getData());
        },
        'click:relay(.action-showmode)':function(e){
            e.preventDefault();
            if(this.hasClass('active')) return;
            toggleActive(this);
            Module.element('gallery.sortbar','input[name=showtype]').value = this.get('data-show-type');
            Query.filter(getData());
        },
        'change:relay(.action-gtags,.action-available)':function(e) {
            Query.filter(getData());
        },
        'click:relay(a.flip:not(.over))':function(e){
            e.preventDefault();
            var self = this;
            Query.filter(getData(this), function(e){
                self.getSiblings('.over').removeClass('over');
                var page = getFlipPage();
                var parent = self.getParent();
                if(page <= 1) parent.getElement('.prev').addClass('over');
                else if(page >= getPage().total) parent.getElement('.next').addClass('over');
            });
        }
    });
    Module.gallery.show.addEvents({
        'click:relay(.action-addtocart)':function(e){
            if(this.target != '_dialog_minicart') {
                var item = this.getParent('.goods-item');
                var num = item.getElement('.action-quantity-input');
                if(!num) return;
                var ginfo = {
                    gid: item.getElement('[name="goods[goods_id]"]').value,
                    pid: item.getElement('[name="goods[product_id]"]').value,
                    num: num.value
                }
                var url = '<{link app=b2c ctl=site_cart act=add arg0=goods arg1="{gid}" arg2="{pid}" arg3="{num}"}>';
                this.href = url.substitute(ginfo);

                // Query.addtocart(this.href, data, this.target);
            }
        },
        'click:relay(.action-notify)': function(e) {
            var id = this.get('rel').split('::');
            var dialog = new Dialog($('product_notify').wrapped(), {
                title:'<{t}>到货通知<{/t}>',
                width: 600,
                modal: {
                    'class': 'cover'
                },
                onLoad: function(){
                    var content = this.content;
                    var holder = content.getElements('input[type=hidden]');
                    var handle = content.getElement('[rel=_request]');
                    holder[0].value = id[0];
                    holder[1].value = id[1];
                    handle && handle.store('_ajax_config',{
                        onSuccess:function(rs){
                            if(rs && rs[0]) {
                                if(rs[0]['true']) {
                                    content.getElement('.product-notify').innerHTML = '<div class="success"><{t}>联系方式已经成功提交，到货后会立刻通知您。<{/t}></div>';
                                    dialog.hide.delay(3000, dialog);
                                }
                            }
                        }
                    });
                }
            });
        },
        'click:relay(.action-compare)': function(e) {
            var container = Module.gallery.compare;
            var content = container.getElement('.content');
            var ul = content.getElement('ul');
            var cpr = container.getElement('.compare-template').innerHTML;
            var info = JSON.decode(this.get('data-compare'));
            var html = cpr.substitute(info);
            var tips = new Tips(this);
            var last;
            if(!ul){
                content.innerHTML = '<ul>' + html + '</ul>';
                showCompareFoot();
                last = content.getElement('.compare-item');
            }
            else {
                var items = ul.getElements('.compare-item');
                var j = items.length;
                if(j == 5) {
                    return tips.show('<{t}>最多只能对比5个商品，请删除之后再添加。<{/t}>');
                }
                for(var i = 0; i < j; i ++){
                    var item = items[i];
                    var rs = JSON.decode(item.get('data-compare'));
                    var type_id = item.getElement('input[name=type_id]').value;
                    var goods_id = item.getElement('input[name^=goods_id]').value;
                    if(info.type_id != type_id) {
                        return tips.show('<{t}>只能对比同类商品！<{/t}>');
                    }
                    if(info.goods_id == goods_id) {
                        return tips.show('<{t}>该商品已加入对比栏。<{/t}>');
                    }
                }
                tips.hide();
                last = new Element('ul', {html: html}).getFirst().inject(ul);
            }
            clearTimeout(container.timer);
            openCompare(container);
            if(Browser.ie6) {
                last.getElement('.action-goods-img').zoomImg(60, 60);
            }
            this.addClass('stat-compared');
            foldCompare(container, 3000);
        },
        'click:relay(a.flip:not(.over))':function(e){
            e.preventDefault();
            Query.filter(getData(this), function(e){
                try{
                    new Fx.Scroll(document.body, {link:'cancel', duration: 0}).toElementEdge(Module.gallery.sortbar);
                }catch(e){}
            });
        }
    });

    Module.gallery.compare.addEvents({
        'click:relay(.action-unfold-compare)': function(e) {
            openCompare();
        },
        'click:relay(.action-fold-compare)': function(e) {
            foldCompare();
        },
        'click:relay(.action-del-compare)': function(e) {
            e.preventDefault();
            var ul = this.getParent('ul');
            if(ul.getChildren().length > 1) {
                this.getParent('.compare-item').destroy();
            }
            else clearCompare();
        },
        'click:relay(.action-goods-compare)':function(e){
            var item = Module.gallery.compare.getElements('.compare-item');
            if(item.length < 2) {
                e.stop();
                var tips = new Tips(this);
                return tips.show('<{t}>对比最少需要有2件商品<{/t}>');
            }

        },
        'click:relay(.action-clear-compare)': function(e) {
            e.preventDefault();
            clearCompare();
        },
        'mouseleave': function(e) {
            foldCompare(this, 3000);
        }
    });
    function getData_no1(el) {
        var cat = 'cat_id=<{$screen.cat_id}>';
        var vcat = 'virtual_cat_id=<{$filter.virtual_cat_id}>';
        var filter= [cat,vcat];
        /*     var param = location.search;
         if(param) {
         param = param.split('?')[1];
         filter.push(param);
         }*/
        var page;
        if(el) page = 'page=' + getFlipPage(el);
        var data = filter.concat(Array.from(Module.gallery.selected.getElements('[data-fid]').get('data-fid')), decodeURI(Module.gallery.sortbar.toQueryString()), page);
        data = data.join('&').replace(/-/g, '[]=');
        data && Memory.set('gallery.filter', data);
        return data;

    }
    function getData(el) {
        var cat = 'cat_id=<{$screen.cat_id}>';
        var vcat = 'virtual_cat_id=<{$filter.virtual_cat_id}>';
        var filter= [cat,vcat];
        var param = location.search;
        if(param) {
            param = param.split('?')[1];
            filter.push(param);
        }
        var page;
        if(el) page = 'page=' + getFlipPage(el);
        var data = filter.concat(Array.from(Module.gallery.selected.getElements('[data-fid]').get('data-fid')), decodeURI(Module.gallery.sortbar.toQueryString()), page);
        data = data.join('&').replace(/-/g, '[]=');
        data && Memory.set('gallery.filter', data);
        // alert(data);
        return data;

    }

    function getData2(el) {
//        var lodingbox='<div class="loding" style="width:100%; height:100%; position:fixed; top:0; left:0;z-index:9999999999;"><div style="width:100px;margin:20% auto;color:#000; "><{img style="display:block;width:100%;" src="images/loading_blue.gif"  app="b2c"}></div></div>';
//        jQuery('#gallery_filter').append(lodingbox);
        var cat = 'cat_id=<{$screen.cat_id}>';
        var vcat = 'virtual_cat_id=<{$filter.virtual_cat_id}>';
        var filter= [cat,vcat];
        var param = location.search;
        if(param) {
            var reg = new RegExp('(^|&)' + 'scontent' + '=([^&]*)(&|$)');
            var r = window.location.search.substr(1).match(reg);
            if(r != null) {
                var keyword = 'scontent=' + r[2];
                keyword = keyword.replace(/-/g, '[]=');
                filter.push(keyword);
            }
        }
        var page;
        if(el) page = 'page=' + getFlipPage(el);
        var  arr = Array.from(Module.gallery.selected.getElements('[data-fid]').get('data-fid'));
        arr.sort();
        var data = filter.concat(arr, decodeURI(Module.gallery.sortbar.toQueryString()), page);
        data = data.join('&').replace(/-/g, '[]=');
        data && Memory.set('gallery.filter', data);

        var parenturl = window.location.pathname;
        if(jQuery('.filter-selected-values').find('span').length<=1){
            var gotourl = parenturl;
        }else{
            var gotourl = parenturl + '?' + data;
        }
        window.location.href = gotourl;
    }

    //延迟加载图片
    new DataLazyLoad({
        img:'data-src',
        lazyDataType:'img',
        onAfter:function(img){
            //ie6下缩放图片
            if(Browser.ie6) {
                fixImageSize(img);
            }
        }
    });
    //商品列表固定4列计算每列宽度并处理列高
    setGridSize(Module.gallery.show.getElements('.gallery-grid .goods-item'), ['.goods-name', '.promotion-tags'], 4);
    if(Browser.ie6) {
        //ie6下对比栏fixed
        Module.gallery.compare.fixed('top');
    }
    function delFilter(el,sel) {
        var items = sel.getSiblings();
        if(items.length == 1) {
            if(el) {
                var parent = el.getParent();
                if(parent.hasClass('filter-item-hide')) parent = parent.getParent();
                parent.getElement('.filter-item').addClass('active');
            }
            items.getParent().destroy();
        }
        else sel.destroy();
        var input = el.getElements('.action-filter-input');
        if(input.length) {
            input.each(function(el){
                el.value = '';
            });
        }
        el && el.removeClass('active');
    }

    function setFilter(el, item, value, min, max) {
        value = value || el.get('text');
        item = item || el.getParent('.filter-item');
        var type = el.getParent('.filter-lists-container') ? '-entries' : el.getParent('.filter-promotion') ? '-promotion' : '-dropdown';
        var id = item.get('data-fid');
        var entries = el.getParent('[data-label]');
        var first = entries.getElement('.filter-item');
        var label = entries.get('data-label');
        var single = entries.get('data-single');
        var name = entries.getElement('.filter'+type+'-label').get('text');
        name =  name + '<{t}>：<{/t}>'; //name.substr(0, name.length - 1) +
        var tpl = value + '<a href="javascript:void(0);" class="action-delete-filter icon iconfont">&#xe62f;</a>';
        var selected = Module.gallery.selected.getElement('.filter-selected-values');
        var selected_item = selected.getElement('[data-label="'+label+'"]');
        single = single ? ' data-single="true"' : '';
        if(first.hasClass('active')) first.removeClass('active');
        if(single) item.getParent().getElements('.active').removeClass('active');
        if(!id || id.test(/custom/) && (min || min === 0) && max) {
            id = label + '-' + min + '~' + max;
        }
        if(!selected_item) {
            tpl = '<span class="filter-selected-entries" data-label="'+label+'"'+single+'><label class="filter-selected-label">'+name+'</label><span class="filter-selected-item" data-fid="'+id+'">'+tpl+'</span></span>';
            new Element('div',{html:tpl}).getFirst().inject(selected);
        }
        else {
            if(single) {
                if(jQuery('.filter-selected-entries').attr('data-label')=='price'){
                    jQuery('.filter-selected-entries').find('span').remove();
                    new Element('span.filter-selected-item', {
                        'data-fid': id,
                        html: tpl
                    }).inject(selected_item);
                }else{
                    selected_item.getElement('.filter-selected-item').set('data-fid', id).innerHTML = tpl;
                }
            }
            else {
                new Element('span.filter-selected-item', {
                    'data-fid': id,
                    html:tpl
                }).inject(selected_item);
            }
        }
    }

    function setCustom(item) {
        var price = item.getNext('[data-fid$=custom]');
        if(price) {
            var area = item.get('data-fid');
            var input = price.getElements('.action-filter-input');
            area = area ? area.split('-')[1].split('~') : [];
            input.each(function(el,i){
                el.value = area[i] || '';
            });
        }
        //$('action-confirm-price').click();
    }

    function getFlipPage(el) {
        var page = getPage().current;
        if(el) {
            if(el.hasClass('next')) page += 1;
            else if(el.hasClass('prev')) page -= 1;
            else page = el.get('text');
        }
        return page;
    }
    function getPage() {
        var pagedata = {};
        var pagelimit = '<{$pageLimit|default:20}>';
        try {
            pagedata = JSON.decode(Module.gallery.show.getElement('.action-pagedata').value) || {};
        }catch(e){}
        return {
            sum: pagedata.total || 0,
            current: pagedata.pagecurrent || 1,
            total: pagedata.pagetotal || 1
        };
    }

    function updateNum() {
        var page = getPage();
        jQuery('.mini-pageview .page-current').innerHTML = page.sum;
        Module.element('gallery.sortbar', '.page-current').innerHTML = page.current;
        Module.element('gallery.sortbar', '.page-total').innerHTML = page.total;
        var prev = Module.element('gallery.sortbar', '.page-action .prev');
        var next = Module.element('gallery.sortbar', '.page-action .next');
        if(page.total == 1) {
            prev.addClass('over');
            next.addClass('over');
        }
        else if(page.total > 1){
            next.removeClass('over');
            if(page.total == page.current) {
                prev.removeClass('over');
                next.addClass('over');
            }
            else {
                if(page.current == 1) {
                    prev.addClass('over');
                }
                else {
                    prev.removeClass('over');
                }
                next.removeClass('over');
            }
        }
    }

    function hideFilterPop(el) {
        if(!el.getElement('input:focus')){
            el.removeClass('filter-pop-active');
        }
    }

    function hideDropdown(el) {
        el.removeClass('current');
    }

    function toggleText(el, attr) {
        attr = attr || 'data-toggle';
        var a = el.get(attr);
        var b = el.get('text');
        el.set(attr, b).set('text', a);
    }

    function toggleActive(el, cls) {
        if(!el) return;
        cls = cls || 'active';
        el.addClass(cls).getSiblings('.'+cls).removeClass(cls);
    }
    /*排序*/
    function toggleOrderby(el, set){
        // if(el.hasClass('active')) return;
        var sel = Module.element('gallery.sortbar', '.action-orderby');
        var sort = '';
        if(el.hasClass('price-desc')) {
            el.swapClass('price-desc', 'price-asc');
            sort = 's_price asc';
            el.set('data-sort', sort);
            jQuery('.desc').css('display','none');
            jQuery('.asc').css('display','inline-block');
        }
        else if(el.hasClass('price-asc')) {
            el.swapClass('price-asc', 'price-desc');
            sort = 's_price desc';
            el.set('data-sort', sort);
            jQuery('.desc').css('display','inline-block');
            jQuery('.asc').css('display','none');
        }
        else {
            var _sort = el.get('data-sort');
            sort = _sort;
            el.set('data-sort', sort);
            jQuery('.asc').css('display','inline-block');
            jQuery('.desc').css('display','none');
        }
        if(set !== false) sel.value = sort;

        //alert(set);
    }

    //== 为数量选择框绑定事件
    bindQuantityEvent(Module.gallery.show,setQuantity);

    function bindQuantityEvent(elements, callback) {
        elements = document.id(elements) || $$(elements);
        if(!elements && !elements.length) return;
        var value = '';
        elements.addEvents({
            //= 数量按钮
            'click:relay(.btn-decrease,.btn-increase)': function(e) {
                var input = this.getParent().getElement('.action-quantity-input');
                value = +input.value;
                input.value = this.hasClass('btn-decrease') ? value - 1 : value + 1;
                callback && callback(input, value);
            },
            //= 数量输入框
            'focus:relay(.action-quantity-input)': function(e){
                value = +this.value;
            },
            'change:relay(.action-quantity-input)': function(e) {
                callback && callback(this, value);
            }
        });
    }
    //== 获取商品数量值
    function getQuantity(el, type) {
        return el.getElement('input[name=' + type + ']').value;
    }
    //== 设置商品数量
    function setQuantity(input, value) {
        var type = 'product';
        inputCheck(input, {min: input.get('min'), max: input.get('max'), 'default': value});
    }
    //== 商品数量输入框正确性检测
    function inputCheck(input, options) {
        if(!input) return false;
        options = options || {};
        if(isNaN(options.min)) options.min = 1;
        if(isNaN(options.max)) options.max = 9999;
        options['default'] = options['default'] || options.min;
        var value = +input.value;
        var tips = new Tips(input);
        var pre = '';
        var msg = '';
        if(options.store && options.store - value <= 0) {
            pre = '<{t}>库存有限，<{/t}>';
        }
        if(value < options.min) {
            input.value = options.min;
            msg = '<{t}>此商品的最小购买数量为<{/t}>' + options.min + '<{t}>件<{/t}>';
        }
        else if(value > options.max){
            input.value = options.max;
            msg = pre + '<{t}>此商品最多只能购买<{/t}>' + options.max + '<{t}>件<{/t}>';
        }
        else if(isNaN(value)) {
            input.value = options['default'];
            msg = '<{t}>只允许输入数字<{/t}>';
        }
        if (msg) {
            tips.show(msg);
            return false;
        }
        tips.hide();
        return true;
    }

    // 商品对比
    function openCompare(o) {
        (o || Module.gallery.compare).addClass('gallery-compare-unfold');
    }
    function foldCompare(o, delay) {
        o = o || Module.gallery.compare;
        if(delay && o.hasClass('gallery-compare-unfold')) {
            o.timer = foldCompare.delay(delay, o, o);
        }
        else o.removeClass('gallery-compare-unfold');
    }
    function clearCompare() {
        var content = Module.element('gallery.compare', '.content');
        content.innerHTML = Module.element('gallery.compare', '.none-template').innerHTML;
        hideCompareFoot();
    }
    function showCompareFoot() {
        Module.element('gallery.compare', '.footer').removeClass('hide');
    }
    function hideCompareFoot() {
        Module.element('gallery.compare', '.footer').addClass('hide');
    }

    //排序箭头问题优化
    function  _test(){
        var _sort =jQuery("#paixu").attr("data-sort");
        _sort =_sort.substring(_sort.lastIndexOf(" ")+1,_sort.length);
        if(_sort=='desc'){
            jQuery('.desc').css('display','inline-block');
            jQuery('.asc').css('display','none');
        }
        else{
            jQuery('.asc').css('display','inline-block');
            jQuery('.desc').css('display','none');
        }
    };
    _test();
</script>
<{require file="block/footer.html"}>
</body>
</html>
